#ifndef __CUHB_ALGOS_HPP__
#define __CUHB_ALGOS_HPP__

/*
  Copyright (c) 2010 Davide Rossetti (davide.rossetti@roma1.infn.it)

  This file is part of CuHB (CUDA Heisenberg) package.
  
  CuHB is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  CuHB is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with CuHB.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "cmath"
#include "rng.hpp"

static inline int mod(int v, size_t l)
{
    return v & (l-1);
}

//-----------------------------------------------------------------------------

static inline vec operator*(const jmat &j, const vec &v)
{
    vec ret = {
        j.j00 * v.x + j.j01 * v.y + j.j02 * v.z,
        j.j10 * v.x + j.j11 * v.y + j.j12 * v.z,
        j.j20 * v.x + j.j21 * v.y + j.j22 * v.z
    };
    return ret;
}

//-----------------------------------------------------------------------------

static inline float operator*(const vec &v1, const vec &v2)
{
    return v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
}

//-----------------------------------------------------------------------------

static inline vec operator*(const float &f, const vec &v)
{
    vec r = {f*v.x, f*v.y, f*v.z};
    return r;
}

//-----------------------------------------------------------------------------

static inline vec operator/(const vec &v, const float &f)
{
    return operator*(1/f, v);
}

//-----------------------------------------------------------------------------

static inline vec& operator+=(vec &v1, const vec &v2)
{
    v1.x += v2.x;
    v1.y += v2.y;
    v1.z += v2.z;
    return v1;
}

//-----------------------------------------------------------------------------

static inline void sincos(float x, float *sin, float *cos)
{
    sincosf(x, sin, cos);
}

//-----------------------------------------------------------------------------
/*
 * Local variables:
 *  mode: c++
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 4
 *  indent-tabs-mode: nil
 * End:
 */

#endif // __CUHB_ALGOS_HPP__

